package smartagdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import smartagdemo.service.impl.UploadServiceImpl;

@RestController
@RequestMapping("SmartAG/upload")
public class UploadController {

    private static String successMessage = "success";
    private static String failMessage = "fail";
    private static String testMessage = "Connect Test Success...";

    @Autowired
    private UploadServiceImpl uploadService;
    //连接测试
    @RequestMapping("/uploadTest")
    public String uploadTest(){
        return testMessage;
    }
    //上传湿度数据
    @RequestMapping("/uploadHumidity")
    public String uploadHumidityDate(@RequestParam String humidity){
        double dHumidity=0;
        dHumidity = Double.valueOf(humidity);
        uploadService.uploadHumidity(dHumidity);
        return successMessage;
    }
    //上传温度数据
    @RequestMapping("/uploadTemperature")
    public String uploadTemperatureDate(@RequestParam String temperature){
        double dTemperature=0;
        dTemperature=Double.valueOf(temperature);
        uploadService.uploadTemperature(dTemperature);
        return successMessage;
    }
    //上传光照数据
    @RequestMapping("/uploadLight")
    public String uploadLightDate(@RequestParam String light){
        double dLight=0;
        dLight=Double.valueOf(light);
        uploadService.uploadLight(dLight);
        return successMessage;
    }
    //上传册数数据
    @RequestMapping("/uploadTestDate")
    public String uploadTestDate(@RequestParam String humidity, @RequestParam String temperature,@RequestParam String light
    ){
//      public String uploadTestDate(@RequestParam TestDate testDate){
        double dHumidity=0,dTemperature=0,dLight=0;
//        dHumidity = Double.valueOf(testDate.getHumidityDate());
//        dTemperature = Double.valueOf(testDate.getTemperatureDate());
//        dLight = Double.valueOf(testDate.getLightDate());
        dHumidity = Double.valueOf(humidity);
        dTemperature = Double.valueOf(temperature);
        dLight = Double.valueOf(light);

        System.out.println(uploadService);
        uploadService.uploadTest(dHumidity,dTemperature,dLight);
        return successMessage;
    }
}
//发送格式样例：http://47.113.217.47:9095/SmartAG/upload/uploadTest?humidity=20.3&temperature=34.4&light=364.348
